﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager

Partial Class MainLayout
    Inherits System.Web.UI.MasterPage

    Protected Sub lnkConfig_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkConfig.Click
        'Session.Remove("Nav")
        Session.Add("Nav", "Config")
        If Session("StaffType").ToString = "2" Then
            trConfiguration.Visible = False
            trTrans.Visible = False
            trListing.Visible = False
            trReport.Visible = False
            trOthers.Visible = False
            trOthersStaff.Visible = False
        Else
            trConfiguration.Visible = True
            trTrans.Visible = False
            trListing.Visible = False
            trReport.Visible = False
            trOthers.Visible = False
            trOthersStaff.Visible = False
            Response.Redirect("Dashboard.aspx")
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' Test for special login
        Dim sPagePath As String = System.Web.HttpContext.Current.Request.Url.AbsolutePath
        Dim oFileInfo As New System.IO.FileInfo(sPagePath)
        Dim sPageName As String = oFileInfo.Name
        System.Diagnostics.Debug.Write(sPagePath)


        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            If Session.Item("StaffType").ToString = "2" Then
                lnkConfig.Visible = False
            End If
            If Session.Item("StaffType").ToString = "7" Then
                lnkConfig.Visible = False
                lnkListing.Visible = False
                lnkOther.Visible = False
                lnkReport.Visible = False
                lnkTransaction.Visible = False
                lnkMobile.Visible = True
                lblUserName.Text = Session("UserName").ToString
                Session.Add("Nav", "Mobile")
                CheckAccessPartimer(sPageName)
            End If

            lblUserName.Text = Session("UserName").ToString
            If Not Session("Nav") Is Nothing Then
                Dim CurrenSession As String = Session("Nav").ToString

                Select Case CurrenSession
                    Case "Config"
                        trConfiguration.Visible = True
                        trTrans.Visible = False
                        trListing.Visible = False
                        trReport.Visible = False
                        trOthers.Visible = False
                        trOthersStaff.Visible = False
                        trMobile.Visible = False
                    Case "List"
                        trListing.Visible = True
                        trTrans.Visible = False
                        trConfiguration.Visible = False
                        trReport.Visible = False
                        trOthers.Visible = False
                        trOthersStaff.Visible = False
                        trMobile.Visible = False
                    Case "Trans"
                        trListing.Visible = False
                        trTrans.Visible = True
                        trConfiguration.Visible = False
                        trReport.Visible = False
                        trOthers.Visible = False
                        trOthersStaff.Visible = False
                        trMobile.Visible = False
                    Case "Report"
                        trListing.Visible = False
                        trTrans.Visible = False
                        trConfiguration.Visible = False
                        trReport.Visible = True
                        trOthers.Visible = False
                        trOthersStaff.Visible = False
                        trMobile.Visible = False
                    Case "Mobile"
                        trListing.Visible = False
                        trTrans.Visible = False
                        trConfiguration.Visible = False
                        trReport.Visible = False
                        trOthers.Visible = False
                        trOthersStaff.Visible = False
                        trMobile.Visible = True
                    Case "Others"
                        If Session.Item("StaffType").ToString = "2" Then
                            trListing.Visible = False
                            trTrans.Visible = False
                            trConfiguration.Visible = False
                            trReport.Visible = False
                            trOthers.Visible = False
                            trOthersStaff.Visible = True
                            trMobile.Visible = False
                        Else
                            trListing.Visible = False
                            trTrans.Visible = False
                            trConfiguration.Visible = False
                            trReport.Visible = False
                            trOthers.Visible = True
                            trOthersStaff.Visible = False
                            trMobile.Visible = False
                        End If
                End Select
            Else
                trListing.Visible = True
                trTrans.Visible = False
                trConfiguration.Visible = False
                trReport.Visible = False
                trOthers.Visible = False
                trOthersStaff.Visible = False
                trMobile.Visible = False
            End If
        End If

        If Not Page.IsPostBack Then
            LoadLogo()
        End If

        imgLogo.ImageUrl = Session("Image")
        lblTitle.Text = Session("TT")
    End Sub

    Private Sub LoadLogo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT CompanyLogo, CompanyName FROM AW_Setting"
        objDB.FillData(TempDT, "Setting", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

       
        Session.Add("Image", "avatar/" & TempDT.Rows(0).Item("CompanyLogo").ToString)
        If Session("TT") Is Nothing Then
            Session.Add("TT", TempDT.Rows(0).Item("CompanyName").ToString)
        End If
    End Sub

    Protected Sub lnkListing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkListing.Click
        'Session.Remove("Nav")
        Session.Add("Nav", "List")
        trListing.Visible = True
        trTrans.Visible = False
        trConfiguration.Visible = False
        trReport.Visible = False
        trOthers.Visible = False
        trOthersStaff.Visible = False
        Response.Redirect("Dashboard.aspx")
    End Sub

    Protected Sub lbtCountry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtCountry.Click
        Session.Add("Nav", "Config")
        Response.Redirect("country.aspx")
    End Sub

    Protected Sub lbtState_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtState.Click
        Session.Add("Nav", "Config")
        Response.Redirect("state.aspx")
    End Sub

    Protected Sub lbtLocation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtLocation.Click
        Session.Add("Nav", "Config")
        Response.Redirect("location.aspx")
    End Sub

    Protected Sub lbtRoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRoad.Click
        Session.Add("Nav", "Config")
        Response.Redirect("road.aspx")
    End Sub

    Protected Sub lbtProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtProject.Click
        Session.Add("Nav", "Config")
        Response.Redirect("project.aspx")
    End Sub

    Protected Sub lbtUnitNumber_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtUnitNumber.Click
        Session.Add("Nav", "Config")
        Response.Redirect("unit.aspx")
    End Sub

    Protected Sub lbtStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtStaff.Click
        Session.Add("Nav", "Config")
        Response.Redirect("staff.aspx")
    End Sub

    Protected Sub lbtPropertyType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtPropertyType.Click
        Session.Add("Nav", "Config")
        Response.Redirect("propertyType.aspx")
    End Sub

    Protected Sub lnkLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLogout.Click
        Session.RemoveAll()
        Session.Clear()
        Response.Redirect("Default.aspx")
    End Sub

    Protected Sub lbtContact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtContact.Click
        Session.Add("Nav", "Config")
        Response.Redirect("contact.aspx")
    End Sub

    Protected Sub lbtSysSetup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtSysSetup.Click
        Session.Add("Nav", "Config")
        Response.Redirect("setup.aspx")
    End Sub
    'lbtLoginStatus
    Protected Sub lbtLoginStatus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtLoginStatus.Click
        Session.Add("Nav", "Config")
        Response.Redirect("LoginStatus.aspx")
    End Sub

    Protected Sub lnkTransaction_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTransaction.Click
        'Session.Remove("Nav")
        Session.Add("Nav", "Trans")
        trListing.Visible = False
        trTrans.Visible = True
        trConfiguration.Visible = False
        trReport.Visible = False
        trOthers.Visible = False
        trOthersStaff.Visible = False
        Response.Redirect("Dashboard.aspx")
    End Sub

    Protected Sub lbtList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtList.Click
        Session.Add("Nav", "List")
        Response.Redirect("propertylist.aspx")
    End Sub

    Protected Sub lbtTranslist_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtTranslist.Click
        Session.Add("Nav", "Trans")
        Response.Redirect("translist.aspx")
    End Sub

    Protected Sub lbtCompleteTransList_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles lbtCompleteTransList.Command
        Session.Add("Nav", "Trans")
        Session.Add("PropertyAt", "Completed")
        Response.Redirect("transcompletelist.aspx")
    End Sub

    'Edited by Tan Chin Teong @ 27/10/2012
    'To point to pending NFS/NFR/SBO/RBO
    Protected Sub lbtNFSRPendingList_Click(sender As Object, e As System.EventArgs) Handles lbtNFSRPendingList.Click
        Session.Add("Nav", "Trans")
        Session.Add("PropertyAt", "NFSR")
        Response.Redirect("transcompletelist.aspx")
    End Sub
    Protected Sub lbtHistoryTransList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtHistoryTransList.Click
        Session.Add("Nav", "Trans")
        Response.Redirect("transHistory.aspx")
    End Sub

    Protected Sub lbtCoBroke_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtCoBroke.Click
        Session.Add("Nav", "Config")
        Response.Redirect("CoBroke.aspx")
    End Sub

    Protected Sub lnkReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkReport.Click
        Session.Add("Nav", "Report")
        trListing.Visible = False
        trTrans.Visible = False
        trConfiguration.Visible = False
        trReport.Visible = True
        trOthers.Visible = False
        trOthersStaff.Visible = False
        Response.Redirect("Dashboard.aspx")
    End Sub

    Protected Sub lbtrptListing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtrptListing.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptListing.aspx")
    End Sub

    Protected Sub lbtrptTransPendCollect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtrptTransPendCollect.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptTransPendCollect.aspx")
    End Sub

    Protected Sub lbtrptTransPendSign_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtrptTransPendSign.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptTransPendSign.aspx")
    End Sub

    Protected Sub lbtrptTtansAbort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtrptTtansAbort.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptTransAbort.aspx")
    End Sub

    Protected Sub lnkOther_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkOther.Click
        Session.Add("Nav", "Others")
        If Session.Item("StaffType").ToString = "2" Then
            trListing.Visible = False
            trTrans.Visible = False
            trConfiguration.Visible = False
            trReport.Visible = False
            trOthers.Visible = False
            trOthersStaff.Visible = True
        Else
            trListing.Visible = False
            trTrans.Visible = False
            trConfiguration.Visible = False
            trReport.Visible = False
            trOthers.Visible = True
            trOthersStaff.Visible = False
        End If
        Response.Redirect("Dashboard.aspx")
    End Sub

    Protected Sub lbtAnnouncement_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtAnnouncement.Click
        Session.Add("Nav", "Others")
        Response.Redirect("Announcementlist.aspx")
    End Sub

    Protected Sub lbtRenTransfer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenTransfer.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenTransfer.aspx")
    End Sub

    Protected Sub lbtRenReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReport.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReport.aspx")
    End Sub
    
    Protected Sub lbtRenReportStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReportStaff.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReport.aspx")
    End Sub

    Protected Sub lbtUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtUpload.Click
        Session.Add("Nav", "Config")
        Response.Redirect("UploadValuation.aspx")
    End Sub

    Protected Sub lbtListAuc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtListAuc.Click
        Session.Add("Nav", "List")
        Response.Redirect("UploadSearch.aspx")
    End Sub

    Protected Sub lbtOldListing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtOldListing.Click
        Session.Add("Nav", "List")
        Response.Redirect("UploadOldListing.aspx")
    End Sub

    Protected Sub lbtDocumentation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtDocumentation.Click
        Session.Add("Nav", "Others")
        Response.Redirect("Documentation.aspx")
    End Sub

    Protected Sub lbtDocumentationStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtDocumentationStaff.Click
        Session.Add("Nav", "Others")
        Response.Redirect("Documentation.aspx")
    End Sub

    Protected Sub lbtRenReportSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReportSearch.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReportSearch.aspx")
    End Sub

    Protected Sub lbtRenReportMeeting_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReportMeeting.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReportMeeting.aspx")
    End Sub

    Protected Sub lbtRenReportSearchStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReportSearchStaff.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReportSearch.aspx")
    End Sub

    Protected Sub lbtRenReportMeetingStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtRenReportMeetingStaff.Click
        Session.Add("Nav", "Others")
        Response.Redirect("RenReportMeeting.aspx")
    End Sub

    Protected Sub lbtTrackingStaff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtTrackingStaff.Click
        Session.Add("Nav", "Others")
        Response.Redirect("rptTracking.aspx")
    End Sub

    Protected Sub lbtrptMonthly_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtrptMonthly.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptMonthlyReport.aspx")
    End Sub

    Protected Sub lbtNFSRList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtNFSRList.Click
        Session.Add("Nav", "Trans")
        Response.Redirect("propertytnotsalerent.aspx")
    End Sub

    Protected Sub lbtrptCommission_Click(sender As Object, e As System.EventArgs) Handles lbtrptCommission.Click
        Session.Add("Nav", "Report")
        Response.Redirect("rptCommissionReport.aspx")
    End Sub


    Protected Sub lbtHistoryTransByDateList_Click(sender As Object, e As EventArgs) Handles lbtHistoryTransByDateList.Click
        Session.Add("Nav", "Trans")
        Response.Redirect("transHistoryByDate.aspx")
    End Sub

    Protected Sub lbtListMobileUser_Click(sender As Object, e As EventArgs) Handles lbtListMobileUser.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("MobileUser.aspx")
    End Sub

    Protected Sub lbtListMobileJob_Click(sender As Object, e As EventArgs) Handles lbtListMobileJob.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("MobileJob.aspx")
    End Sub
    Protected Sub lbtListAuction_Click(sender As Object, e As EventArgs) Handles lbtListAuction.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("Auction.aspx")
    End Sub

    Protected Sub lbtListNewLaunch_Click(sender As Object, e As EventArgs) Handles lbtListNewLaunch.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("NewLaunch.aspx")
    End Sub

    Protected Sub lbtListMobileNews_Click(sender As Object, e As EventArgs) Handles lbtListMobileNews.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("NewsList.aspx")
    End Sub

    Protected Sub lbtNewsEntry_Click(sender As Object, e As EventArgs) Handles lbtNewsEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("NewsEntry.aspx")
    End Sub

    Protected Sub lbtListUsefulInfo_Click(sender As Object, e As EventArgs) Handles lbtListUsefulInfo.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("UsefulList.aspx")
    End Sub

    Protected Sub lbtUsefulEntry_Click(sender As Object, e As EventArgs) Handles lbtUsefulEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("UsefulInfoEntry.aspx")
    End Sub

    Protected Sub lbtListEvent_Click(sender As Object, e As EventArgs) Handles lbtListEvent.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("EventList.aspx")
    End Sub

    Protected Sub lbtEventEntry_Click(sender As Object, e As EventArgs) Handles lbtEventEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("EventEntry.aspx")
    End Sub


    Protected Sub lbtNewLaunch_Click(sender As Object, e As EventArgs) Handles lbtNewLaunch.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("NewLaunchEntry.aspx")
    End Sub


    Protected Sub lbtPropertyDirectory_Click(sender As Object, e As EventArgs) Handles lbtPropertyDirectory.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("PropertyDirectory.aspx")
    End Sub

    Protected Sub lbtPropertyDirectoryEntry_Click(sender As Object, e As EventArgs) Handles lbtPropertyDirectoryEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("PropertyDirectoryEntry.aspx")
    End Sub

    Protected Sub lbtAuction_Click(sender As Object, e As EventArgs) Handles lbtAuction.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("AuctionEntry.aspx")
    End Sub

    Protected Sub lbtMobileSetting_Click(sender As Object, e As EventArgs) Handles lbtMobileSetting.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("MobileSetting.aspx")
    End Sub

    Protected Sub lnkMobile_Click(sender As Object, e As EventArgs) Handles lnkMobile.Click
        Session.Add("Nav", "Mobile")
        If Session("StaffType").ToString = "1" Or Session("StaffType").ToString = "3" Then
            lbtMobileSetting.Visible = True
        ElseIf Session("StaffType").ToString = "7" Then
            lbtMobileSetting.Visible = False
            lbtMobileSetting.Enabled = False
            lbtListMobileUser.Visible = False
            lbtListMobileUser.Visible = False
        Else
            lbtMobileSetting.Visible = False
            lbtMobileSetting.Enabled = False
        End If
        Response.Redirect("Dashboard.aspx")
    End Sub

    Protected Sub lbtListTransact_Click(sender As Object, e As EventArgs) Handles lbtListTransact.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("RecentTransaction.aspx")
    End Sub

    Protected Sub lbtTransactEntry_Click(sender As Object, e As EventArgs) Handles lbtTransactEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("RecentTransactionEntry.aspx")
    End Sub

    Protected Sub LinkListSellLet_Click(sender As Object, e As EventArgs) Handles LinkListSellLet.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("MobileSellLet.aspx")
    End Sub

    Protected Sub LinkListBuyRent_Click(sender As Object, e As EventArgs) Handles LinkListBuyRent.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("MobileBuyRent.aspx")
    End Sub

    Protected Sub CheckAccessPartimer(pageName As String)
        Dim AllowPages() As String = {"Dashboard.aspx", "AuctionEntry.aspx", "Auction.aspx", "UploadPhoto.aspx", "NewLaunch.aspx",
                                      "NewLaunchEntry.aspx", "PropertyDirectory.aspx", "PropertyDirectoryEntry.aspx",
                                      "NewsList.aspx", "NewsEntry.aspx", "UsefulList.aspx", "UsefulInfoEntry.aspx",
                                      "EventList.aspx", "EventEntry.aspx", "RecentTransaction.aspx",
                                      "RecentTransactionEntry.aspx"}
        If AllowPages.Contains(pageName, StringComparer.CurrentCultureIgnoreCase) Then
            'System.Diagnostics.Debug.Write(pageName & "- Allow")
        Else
            'System.Diagnostics.Debug.Write(pageName & "- DisAllow")
            Response.Redirect("Dashboard.aspx")
        End If
    End Sub

    Protected Sub lbtGalleryEntry_Click(sender As Object, e As EventArgs) Handles lbtGalleryEntry.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("GalleryEntry.aspx")
    End Sub
    Protected Sub LinkListGallery_Click(sender As Object, e As EventArgs) Handles LinkListGallery.Click
        Session.Add("Nav", "Mobile")
        Response.Redirect("Gallery.aspx")
    End Sub
End Class

